package com.copsoftware.hibernate.cfg;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class HibernateUtils {
	private static final Log log = LogFactory.getLog(HibernateUtils.class);
    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure("/com/copsoftware/hibernate/cfg/hibernate.cfg.xml").buildSessionFactory();           
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
           System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }	

    public static void main (String []args)
    {

            try {
                // Create the SessionFactory from hibernate.cfg.xml
                new Configuration().configure("/com/copsoftware/hibernate/cfg/hibernate.cfg.xml").buildSessionFactory();           
            } catch (Throwable ex) {
                // Make sure you log the exception, as it might be swallowed
                System.err.println("Initial SessionFactory creation failed." + ex);
//              
    }}

}
